package com.core.framework.web.easyweb.forward;

import javax.servlet.http.HttpServletRequest;

public class ForwardHelp {
	public  String getPathWithOutExt(HttpServletRequest request) {
		// Log.debug(request.getRequestURI());
		String path = request.getRequestURI();
		if (path.startsWith(request.getContextPath()))
			path = request.getRequestURI().substring(
					request.getContextPath().length());
		if (path.indexOf(".") > 0) {
			path = path.substring(0, path.lastIndexOf("."));
		}
		path = path.replaceAll("/{1}", "/");
		return path;
	}

	public  String getActionMethod(HttpServletRequest request) {
		String path = getPathWithOutExt(request);
		if (path.indexOf("!") > 0) {
			path = path.substring(path.lastIndexOf("!") + 1);
		} else {
			return "index";
		}
		return path;
	}
	public  String getActionPath(HttpServletRequest request) {
		String path = this.getPathWithOutExt(request);
		if (path.indexOf("!") > 0) {
			path = path.substring(0, path.lastIndexOf("!"));
		}
		if (path != null)
			path = path.replaceAll("/{2,}", "/");
		return path;
	}
}
